<?php

class FraisController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        $lesFrais = new Application_Model_DbTable_Frais();
        $this->view->lesFrais = $lesFrais->fetchAll();
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }
    public function gererAction() {
        $lesFrais = new Application_Model_DbTable_Frais();
        $this->view->lesFrais = $lesFrais->fetchAll();
        $this->view->setEscape('htmlentities');
        $this->view->setEncoding('ISO-8859-1');
    }
    

    public function modifierAction() {

        $form = new Application_Form_Frais;
        $form->envoyer->setLabel('Sauvegarder');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $montant = $form->getValue('montant');
                $lesFrais = new Application_Model_DbTable_Frais();
                $lesFrais->modifierFrais($id, $montant);
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            $lesFrais = new Application_Model_DbTable_Frais();
            $form->populate($lesFrais->obtenirFrais($id));
        }
    }

}

